package com.chinaunicom.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author liry
 * @version 1.0
 * @date Created on 2021/3/29 22:05
 * Description: 自定义全局日志过滤器
 */

@Component
public class GlobalLoggerFilter implements GlobalFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

        // 前置处理
        System.out.println("全局日志处理： 前置处理");

        // 后续逻辑处理
        Mono<Void> filter = chain.filter(exchange);

        // 后置处理
        System.out.println("全局日志处理: 后置处理器");

        return filter;
    }
}
